//
//  HandyJSON+Extension.swift
//  BKL_HealthProject
//
//  Created by gePengFei on 2018/7/26.
//  Copyright © 2018年 yunjing. All rights reserved.
//

import RxSwift
import HandyJSON
import Moya

extension ObservableType where E == Response {
    public func mapModel<T :HandyJSON>(_ type: T.Type) -> Observable<T>{
        return flatMap({ (response) -> Observable<T> in
            return Observable.just(response.mapModel(T.self))
        })
    }
}

extension Response {
    func mapModel<T :HandyJSON>(_ T :T.Type) -> T {
        let jsonString = String(data: data, encoding: .utf8)
        return JSONDeserializer<T>.deserializeFrom(json: jsonString)!
    }
}
